package com.ikas.ai.framework.statistics.function;

import com.google.common.collect.Lists;
import com.ikas.ai.framework.statistics.StatisticType;

import java.util.List;
import java.util.Optional;

/**
 * @Description: 最小值
 * @Author: qi.yilai
 * @Date: 2023/10/27 18:10
 * @Version: 1.0.0
 **/
public class MinCalcFunction implements CalcFunction<List<? extends Number>, Long, Long, Double> {

    @Override
    public Double calculate(List<? extends Number> list) {
        Optional<Double> optional = (Optional<Double>) list.stream().max((t1, t2) -> {
            if (t1.doubleValue() > t2.doubleValue()) {
                return -1;
            } else {
                return 1;
            }
        });
        if (optional.isPresent()) {
            return optional.get();
        }
        return 0d;
    }

    @Override
    public Double calculate(List<? extends Number> list, Long aLong, Long aLong2) {
        throw new UnsupportedOperationException("不支持利用临时变量简化计算");
    }

    @Override
    public StatisticType type() {
        return StatisticType.MIN;
    }

    public static void main(String[] args) {
        System.out.println(new MinCalcFunction().calculate(Lists.newArrayList(1, 56f, 43.45, -34.78d)));
    }
}
